/*
package com.zlx.mall.biz.attribution.job;

import com.zlx.mall.base.entity.BasicPointData;
import com.zlx.mall.base.service.IBasicPointDataService;
import com.zlx.mall.basic.common.holder.ApplicationPropertiesHolder;
import com.zlx.mall.basic.common.model.SystemParam;
import com.zlx.mall.basic.quartz.AbstractQuartzJobBean;
import com.zlx.mall.basic.util.json.JacksonUtil;
import com.zlx.mall.basic.util.time.MoreDateTimeUtil;
import com.zlx.mall.biz.attribution.constant.AttributionCacheConstants;
import com.zlx.mall.biz.attribution.model.PointDataLine;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

*/
/**
 * @author qingke
 **//*

@Slf4j(topic = "quartzLogger")
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class PointDataSaveJob extends AbstractQuartzJobBean {

    @Resource
    private IBasicPointDataService basicPointDataService;
    @Resource
    private RedissonClient redissonClient;

    private RBucket<String> getCache() {
        return redissonClient.getBucket(
                String.format(AttributionCacheConstants.POINT_DATA_LATEST_CACHE_KEY,
                        MoreDateTimeUtil.formatCompactDate(LocalDate.now())), StringCodec.INSTANCE);
    }

    @Nullable
    private String getLatestFileName() {
        return getCache().get();
    }

    private void setLatestFileName(String fileName) {
        getCache().set(fileName, Duration.ofDays(1).getSeconds(), TimeUnit.SECONDS);
    }

    private String getDefaultLogFilePath() {
        return ApplicationPropertiesHolder.getProperty("logging.file.path") + "/" +
                ApplicationPropertiesHolder.APPLICATION_NAME;
    }

    private String getLogFilePath(@NonNull JobExecutionContext context) {
        PointDataSaveJobData jobData = parseJobData(context, PointDataSaveJobData.class);
        String logFilePath = StringUtils.hasText(jobData.getLogFilePath()) ? jobData.getLogFilePath() : getDefaultLogFilePath();
        return logFilePath + "/" + MoreDateTimeUtil.formatCompactDate(LocalDate.now()) + "/" + "attribution" + "/";
    }

    @Override
    protected void executeInternal(@NonNull JobExecutionContext context)
            throws JobExecutionException {
        try {
            String logFilePath = getLogFilePath(context);

            File[] files = Paths.get(logFilePath).toFile().listFiles();
            if (Objects.nonNull(files)) {
                File file = Arrays.stream(files).max(Comparator.comparing(File::lastModified)).orElse(null);
                if (file != null) {
                    if (file.getName().equals(getLatestFileName())) {
                        return;
                    }
                    try (Stream<String> lines = Files.lines(file.toPath())) {
                        List<BasicPointData> entities = new ArrayList<>();
                        lines.forEach(line -> {
                            try {

                                PointDataLine data = JacksonUtil.toObject(line, PointDataLine.class);
                                BasicPointData entity = Objects.nonNull(data.getContent()) ?
                                        JacksonUtil.toObject(data.getContent(), BasicPointData.class) : new BasicPointData();
                                SystemParam systemParam = Optional.ofNullable(data.getSystemParam()).orElse(new SystemParam());
                                entity.setTraceId(data.getTraceId());
                                entity.setAppCode(systemParam.getAppCode());
                                entity.setChannelCode(systemParam.getChannel());
                                entity.setUserId(ObjectUtils.getDisplayString(data.getUserId()));
                                entity.setEventTimestamp(ObjectUtils.getDisplayString(data.getTimestamp()));
                                entity.setRemoteAddress(data.getRemoteAddress());
                                entity.setDeviceId(systemParam.getDeviceId());
                                entity.setApkVersion(systemParam.getAppVersion());
                                entity.setNetworkType(systemParam.getNetworkType());
                                entity.setOsType(systemParam.getClientType());
//                                entity.setOsVersion(systemParam.getClientOsVersion());
//                                entity.setOsLanguage(systemParam.getClientOsLanguage());
                                entity.setOsModel(systemParam.getDeviceType());
                                entities.add(entity);

                            } catch (Exception e) {
                                log.error("Parse Point Data Exception", e);
                            }
                        });

                        if (!CollectionUtils.isEmpty(entities)) {
                            if (basicPointDataService.saveBatch(entities)) {
                                setLatestFileName(file.getName());
                            } else {
                                throw new IllegalStateException("Batch Save Point Data Failed");
                            }
                        }
                    }
                }
            }

        } catch (Exception e) {
            throw new JobExecutionException(e);
        }
    }
}
*/
